<?php

namespace Aspic;

use Aspic as A;
use Aspic\Security\Security as S;

class Exception extends \Exception {

	/**
	 * @param array|string The exception message or array('message with ? params ?', $param1, $param2)
	 * @param bool $textOnly If true, $message will be escaped for html
	 */
	public function __construct($messageData, $textOnly = true, $code = 0, \Exception $previous = null) {
		if (is_array($messageData)) {
			$message = $messageData[0];
			$messageParams = array_slice($messageData, 1);

			$message = UString::fromArgsArray($message, $messageParams);
		}
		else {
			$message = $messageData;
		}

		if ($textOnly) {
			$message = S::escapeXss($message, S::ESCAPE_FUNC_ENTITIES, ENT_NOQUOTES);
		}

		parent::__construct($message, $code, $previous);
	}

}
